package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.GoodsOrderDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.GoodsOrderInfo;
import com.sls.game.querybean.GoodsOrderQuery;

/**
 * 
 * @description 网游充值订单表DAO操作
 * @author Wangxuegang
 * @date 2012-9-6
 * 
 */
@Repository("goodsOrderDAO")
public class GoodsOrderDAOImpl extends SuperDAO<GoodsOrderInfo> implements
		GoodsOrderDAO {
	/**
	 * 插入
	 * 
	 * @param goodsOrderInfo
	 */
	@Override
	public void insert(GoodsOrderInfo goodsOrderInfo) {
		this.getSqlSession().insert("mybatis.xml.GoodsOrderMapper.insert",
				goodsOrderInfo);

	}

	/**
	 * 更新
	 * 
	 * @param goodsOrderInfo
	 */
	@Override
	public void update(GoodsOrderInfo goodsOrderInfo) {
		this.getSqlSession().update("mybatis.xml.GoodsOrderMapper.update",
				goodsOrderInfo);

	}

	/**
	 * 订单查询(单条记录)
	 * 
	 * @param orderId
	 *            订单编号
	 */
	@Override
	public GoodsOrderInfo queryByOrderId(String orderId) {
		GoodsOrderInfo goodsOrderInfo = null;
		goodsOrderInfo = this.getSqlSession().selectOne(
				"mybatis.xml.GoodsOrderMapper.queryByOrderId", orderId);
		return goodsOrderInfo;
	}

	/**
	 * 订单查询(符合条件的多条记录)
	 * 
	 * @param goodsOrderInfo
	 * 
	 */
	@Override
	public GoodsOrderInfo query(GoodsOrderInfo goodsOrderInfo) {
		// ...
		return null;
	}

	/**
	 * 根据商户订单号和用户账号，查询记录相关信息
	 * 
	 * @param merchantOrderId
	 * @return
	 */
	@Override
	public GoodsOrderInfo queryByMerchantOrderId(GoodsOrderInfo goodsOrderInfo) {
		GoodsOrderInfo info = null;
		info = this.getSqlSession().selectOne(
				"mybatis.xml.GoodsOrderMapper.queryByMerchantOrderId",
				goodsOrderInfo);
		return info;
	}

	/**
	 * 查询手拉手订单编号最大的记录
	 * 
	 * @return
	 */
	@Override
	public String queryMaxOrderId() {
		String maxOrderId = null;
		maxOrderId = this.getSqlSession().selectOne(
				"mybatis.xml.GoodsOrderMapper.queryMaxOrderId");

		return maxOrderId;
	}

	/**
	 * 根据下游用户账号和下游用户订单号，查询单条记录
	 * 
	 * @param goodsOrderInfo
	 * @return
	 */
	@Override
	public String queryOrderIsExtisOfUserNo(GoodsOrderInfo goodsOrderInfo) {
		String id = null;
		id = this.getSqlSession().selectOne(
				"mybatis.xml.GoodsOrderMapper.queryOrderIsExtisOfUserNo",
				goodsOrderInfo);

		return id;
	}

	@Override
	public Pagination<GoodsOrderInfo> queryOrders(GoodsOrderQuery orderQuery) {
		Integer rows = this.queryRowCount(orderQuery);
		orderQuery.calculate();
		List<GoodsOrderInfo> list = this.queryOrderInfoList(orderQuery);
		Pagination<GoodsOrderInfo> page = super.queryPagination(rows, list,
				orderQuery);
		return page;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param pageInruire
	 * @return
	 */
	private Integer queryRowCount(GoodsOrderQuery orderQuery) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.GoodsOrderMapper.queryOrderInfoRow", orderQuery);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param goodsManageInfo
	 * @return
	 */
	private List<GoodsOrderInfo> queryOrderInfoList(GoodsOrderQuery orderQuery) {
		List<GoodsOrderInfo> list = this.getSqlSession().selectList(
				"mybatis.xml.GoodsOrderMapper.queryOrderInfoList", orderQuery);
		return list;
	}

	@Override
	public List<String> querySupplyNameList() {
		List<String> nameList = this.getSqlSession().selectList(
				"mybatis.xml.GoodsOrderMapper.querySupplyNameList");
		return nameList;
	}

	@Override
	public List<GoodsOrderInfo> queryOrderInfoBySupplyName(
			GoodsOrderInfo goodsOrderInfo) {
		List<GoodsOrderInfo> list = this.getSqlSession().selectList(
				"mybatis.xml.GoodsOrderMapper.queryOrderInfoBySupplyName",
				goodsOrderInfo);
		return list;
	}

	/**
	 * 根据订单编号，查询回调地址
	 * 
	 * @param orderId
	 * @return
	 */
	@Override
	public GoodsOrderInfo queryNotifyUrlByOrderId(String orderId) {
		GoodsOrderInfo info = null;
		info = this.getSqlSession()
				.selectOne(
						"mybatis.xml.GoodsOrderMapper.queryNotifyUrlByOrderId",
						orderId);
		return info;
	}

	/**
	 * 查询未异步推送给下游的订单记录
	 * 
	 * @param synOrAsy
	 * @return
	 * @author Wangxg
	 * @date 2013-01-31
	 */
	@Override
	public List<GoodsOrderInfo> queryGoodsOrderInfoList(String synOrAsy) {
		List<GoodsOrderInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.GoodsOrderMapper.queryGoodsOrderInfoList",
				synOrAsy);
		return list;
	}

	/**
	 * 根据上游供应商编号、支付状态成功、订单状态处理中查询相关记录
	 * 
	 * @param goodsOrderInfo
	 * @return
	 * @date 2013-03-22
	 */
	@Override
	public List<GoodsOrderInfo> queryOrderBySomeConditions(
			GoodsOrderInfo goodsOrderInfo) {
		List<GoodsOrderInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.GoodsOrderMapper.queryOrderBySomeConditions",
				goodsOrderInfo);
		return list;
	}

	/**
	 * 查询订单中的工号列表
	 * 
	 * @return
	 */
	@Override
	public List<GoodsOrderQuery> queryRegisterAccount(GoodsOrderQuery goodsOrderQuery) {
		List<GoodsOrderQuery> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.GoodsOrderMapper.queryRegisterAccount",goodsOrderQuery);
		return list;
	}

	@Override
	public Long queryOrderTotalPrice(GoodsOrderQuery goodsOrderQuery) {
		Long total = this.getSqlSession().selectOne(
				"mybatis.xml.GoodsOrderMapper.queryOrderTotalPrice", goodsOrderQuery);
		return total;
	}

	@Override
	public Long queryOrderCostTotalPrice(GoodsOrderQuery goodsOrderQuery) {
		Long costTotal = this.getSqlSession().selectOne(
				"mybatis.xml.GoodsOrderMapper.queryOrderCostTotalPrice", goodsOrderQuery);
		return costTotal;
	}

	@Override
	public Long queryOrderTotalParvalue(GoodsOrderQuery goodsOrderQuery) {
		Long parvalueTotal = this.getSqlSession().selectOne(
				"mybatis.xml.GoodsOrderMapper.queryOrderTotalParvalue", goodsOrderQuery);
		return parvalueTotal;
	}

	@Override
	public Long queryOrderTotalNum(GoodsOrderQuery goodsOrderQuery) {
		Long numTotal = this.getSqlSession().selectOne(
				"mybatis.xml.GoodsOrderMapper.queryOrderTotalNum", goodsOrderQuery);
		return numTotal;
	}

}
